package com.noisyair.android.alvin.apps.contacts;

import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.noisyair.android.alvin.Talker;
import com.noisyair.android.alvin.activities.AlvinListActivity;

public class AlvinContactPicker extends AlvinListActivity {

	private ListAdapter mAdapter;
	private boolean mShouldRetSms = true;
    static final int PICK_CONTACT_SMS_REQUEST = 9999;
 
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
			
		// first check to see if we should be returning sms info:
		// This doesnt work right now... FIX
		/*
		Intent i = getIntent();
		String wantsSMS = i.getStringExtra("wantsSMS");
		if(wantsSMS != null){
			mShouldRetSms = true;
		}
		*/
		mShouldRetSms = true;
		
		Cursor C = getContentResolver().query(People.CONTENT_URI, null, People.NAME + "!=''", null, People.NAME + " ASC");
		startManagingCursor(C);

		String[] columns = new String[] {People.NAME	};
		int[] names = new int[] {R.id.row_entry};

		mAdapter = new SimpleCursorAdapter(this, R.layout.main, C, columns, names);
		setListAdapter(mAdapter);
}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
			Intent i = new Intent();
			Cursor C = (Cursor) mAdapter.getItem(position);
			i.putExtra("name", C.getString(C.getColumnIndex(People.NAME)));
			i.putExtra("number", C.getString(C.getColumnIndex(People.NUMBER)));
			this.setResult(RESULT_OK, i);
			finish();
		//}
		
		/*
		Intent i = new Intent(Intent.ACTION_CALL);
		Cursor C = (Cursor) mAdapter.getItem(position);
		long phoneId = C.getLong(C.getColumnIndex(People.PRIMARY_PHONE_ID));
		//i.setData(Phones.NUMBER
		//i.setData(Phones.CONTENT_URI.addId(phoneId));
		i.setData(Uri.withAppendedPath(Phones.CONTENT_URI, ("" + phoneId)));
		startActivity(i);
		*/
	}
	
}